//# sourceURL=http://uMapApp/Module/PQI/PQIStaModule
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "../Module"
    , "../../UI/Panel/FloatPanel"
    , "../../UI/Panel/PanelBlock/PanelBlock"
    , "../../UI/Panel/PanelBlock/TableBlock"
    , "../../UI/Panel/PanelBlock/ChartBlock"
    , "../../UI/Panel/Item/ListItem"
    , "../../UI/Layer"
    , "./PQIStatistic"
    , "./PQIBlock"
    , "../Road/StakeNumPanel"
    , "../../UI/Panel/PanelBlock/DataPanelBlock"
    , "../StakeNum/Mileage"
    , "../../UI/QueryNode"
], function (
    mhjs
    , uMap
    , uEarth
    , Module
    , FloatPanel
    , PanelBlock
    , TableBlock
    , ChartBlock
    , ListItem
    , Layer
    , PQIStatistic
    , PQIBlock
    , StakeNumPanel
    , DataPanelBlock
    , Mileage
    , QueryNode
) {

    function PQIStaModule(option) {

        var _this = this;

        Module.call(_this, option);

        _this.title = "PQI统计";
        _this.icon = _this.app.icons.PQI;

        _this.panels = [];
        _this.items = [];
        _this.currentStatisticsOption = {};
        _this.currentList = [];

        _this.directionCodeDic = {
            "U" : "上行",
            "D" : "下行",
            "UD": "双向"
        };

        //全局数据面板
        _this.globeChartPanel = new FloatPanel({"class": "leftPanel", "showMinMax": true, "title": "统计图表"});
        _this.globeChartPanel.hisBlock = new ChartBlock({
            "title": "历史数据",
            "chart": {
                "height"     : 270,
                "width"      : 340,
                "chartOption": {
                    legend : {
                        textStyle: {
                            color: "#fff"
                        }
                    },
                    grid   : {
                        left        : "3%",
                        right       : "4%",
                        bottom      : "3%",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "axis",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    xAxis  : {
                        type         : "category"
                        , boundaryGap: false
                    },
                    yAxis  : {
                        type: "value"
                    },
                    series : [{
                        type: "line"
                        // , areaStyle: {}
                    }]
                }
            }
        });
        _this.globeChartPanel.pieBlock = new ChartBlock({
            "title": "路面等级统计",
            "chart": {
                "height"     : 270,
                "width"      : 340,
                "chartOption": {
                    legend : {
                        type     : "scroll",
                        orient   : "vertical",
                        left     : "left",
                        textStyle: {
                            color: "#fff"
                        }
                    },
                    grid   : {
                        left        : "3%",
                        right       : "4%",
                        bottom      : "3%",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    series : {
                        type  : "pie",
                        center: ["65%", "50%"],
                        label : {
                            formatter: "{b}: {d}%",
                            color    : "#fff"
                        }
                    }
                }
            }
        });

        _this.globeChartPanel.pieBlock.chart.chart.on("click", "series", function (event) {

            if (_this.listPanel.tableBlock.levelSelect.value !== event.name) {
                _this.listPanel.tableBlock.levelSelect.selectValue(event.name);
            } else {
                _this.listPanel.tableBlock.levelSelect.selectValue("");
            }

        });

        _this.globeChartPanel
            .append(_this.globeChartPanel.hisBlock)
            .append(_this.globeChartPanel.pieBlock)
        ;

        _this.app.ui.layout.left.append(_this.globeChartPanel);
        _this.panels.push(_this.globeChartPanel);

        //对比图表面板
        _this.compareChartPanel = new FloatPanel({
            "class": "PQIStaModule compareChartPanel leftPanel", "showClose": "true"
        });
        _this.compareChartPanel.lineBlock = new ChartBlock({
            "title": "超标里程对比",
            "chart": {
                "height"     : 270,
                "width"      : 340,
                "chartOption": {
                    tooltip: {
                        textStyle: {
                            color: "rgba(255, 255, 255, 0.3)"
                        }
                    },
                    series : [
                        {
                            type  : "pie",
                            radius: ["40%", "70%"],
                            data  : [
                                {
                                    value: 1048,
                                    name : "1"
                                },
                                {
                                    value: 735,
                                    name : "2"
                                },
                                {
                                    value: 580,
                                    name : "3"
                                }
                            ]
                        }
                    ]
                }
            }
        });
        _this.compareChartPanel.tableBlock = new PanelBlock({"title": "超标里程对比", "class": "compareTableBlock"});
        _this.compareChartPanel.listBlock = new PanelBlock({"title": "超标里程明细", "class": "compareListBlock"});

        _this.compareChartPanel
        // .append(_this.compareChartPanel.lineBlock)
            .append(_this.compareChartPanel.tableBlock)
            .append(_this.compareChartPanel.listBlock)
        ;

        _this.app.ui.layout.left.append(_this.compareChartPanel);
        _this.panels.push(_this.compareChartPanel);

        //整体数据概览
        _this.globeDataPanel = new FloatPanel({"class": "PQIStaModule globeDataPanel", "showClose": true});

        _this.globeDataPanel.label = new mhjs.Div({"class": "label"});
        _this.globeDataPanel.label.text("关键指标");

        _this.globeDataPanel.distanceData = new DataPanelBlock({
            label  : "通车里程"
            , count: "49.947"
            , unit : "KM"
        });

        _this.globeDataPanel.PQIData = new DataPanelBlock({
            label  : "PQI"
            , count: "0"
        });

        _this.globeDataPanel.MQIData = new DataPanelBlock({
            label  : "MQI"
            , count: "-"
        });

        _this.globeDataPanel.traficData = new DataPanelBlock({
            label  : "实时流量"
            , count: "-"
            , unit : "辆"
        });

        _this.globeDataPanel
            .append(_this.globeDataPanel.label)
            .append(_this.globeDataPanel.distanceData)
            .append(_this.globeDataPanel.PQIData)
            .append(_this.globeDataPanel.MQIData)
            .append(_this.globeDataPanel.traficData)
        ;

        _this.app.ui.layout.top.append(_this.globeDataPanel);
        _this.panels.push(_this.globeDataPanel);

        //整体功能按钮
        _this.globeButtonPanel = new FloatPanel({"class": "PQIStaModule globeButtonPanel"});

        _this.globeButtonPanel.label = new mhjs.Div({"class": "label"});
        _this.globeButtonPanel.label.text("筛选");

        _this.globeButtonPanel.directSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.directSelect.setList([
            {
                "text" : "双向",
                "value": ""
            },
            {
                "text" : "上行",
                "value": "U"
            }, {
                "text" : "下行",
                "value": "D"
            }
        ]);

        _this.globeButtonPanel.roadLineSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.roadLineSelect.setList([
            {
                "text" : "所有车道",
                "value": ""
            },
            {
                "text" : "单向整体",
                "value": "0"
            },
            {
                "text" : "第一车道",
                "value": "1"
            },
            {
                "text" : "第二车道",
                "value": "2"
            },
            {
                "text" : "第三车道",
                "value": "3"
            }
        ]);

        _this.globeButtonPanel.roadLineSelect.selectValue("0");

        _this.globeButtonPanel.startStakeNumInput = new mhjs.Input({"class": "input"});
        _this.globeButtonPanel.startStakeNumInput.placeholder = "请输入起点桩号";

        _this.globeButtonPanel.stopStakeNumInput = new mhjs.Input({"class": "input"});
        _this.globeButtonPanel.stopStakeNumInput.placeholder = "请输入终点桩号";

        _this.globeButtonPanel.yearSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.yearSelect.setList([
            {
                "text" : "2020",
                "value": "2020"
            }, {
                "text" : "2021",
                "value": "2021"
            }, {
                "text" : "2022",
                "value": "2022"
            }
        ]);

        _this.globeButtonPanel.yearSelect.selectValue("2022");

        _this.globeButtonPanel.standardSelect = new mhjs.Select({"class": "select"});
        _this.globeButtonPanel.standardSelect.setList([
            {
                "text" : "国标",
                "value": "GB"
            }, {
                "text" : "省内",
                "value": "JS"
            }

        ]);

        _this.globeButtonPanel.standardSelect.on("select", function (select) {
            _this.toggleStandard(select.value);
        });

        _this.globeButtonPanel.searchButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.searchButton.text("查询");

        _this.globeButtonPanel.searchButton.on("click", function () {
            _this.renderData({
                "directionCode": _this.globeButtonPanel.directSelect.value,
                "roadLineNum"  : _this.globeButtonPanel.roadLineSelect.value,
                "startStakeNum": _this.globeButtonPanel.startStakeNumInput.value,
                "endStakeNum"  : _this.globeButtonPanel.stopStakeNumInput.value,
                "year"         : _this.globeButtonPanel.yearSelect.value
            });
        });

        _this.globeButtonPanel.globeDataButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.globeDataButton.text("总览");

        _this.globeButtonPanel.globeDataButton.on("click", function () {
            _this.globeDataPanel.toggle();
        });

        _this.globeButtonPanel.statisticsButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.statisticsButton.text("统计");

        _this.globeButtonPanel.statisticsButton.on("click", function () {
            _this.openStatistics();
        });

        _this.globeButtonPanel.detailButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.detailButton.text("明细");

        _this.globeButtonPanel.detailButton.on("click", function () {
            _this.openDetail();
        });

        _this.globeButtonPanel.compareButton = new mhjs.Div({"class": "button"});
        _this.globeButtonPanel.compareButton.text("对比");

        _this.globeButtonPanel.compareButton.on("click", function () {
            _this.compareChartPanel.toggle();
        });

        _this.globeButtonPanel
            .append(_this.globeButtonPanel.label)
            .append(_this.globeButtonPanel.directSelect)
            .append(_this.globeButtonPanel.roadLineSelect)
            .append(_this.globeButtonPanel.startStakeNumInput)
            .append(_this.globeButtonPanel.stopStakeNumInput)
            .append(_this.globeButtonPanel.yearSelect)
            .append(_this.globeButtonPanel.searchButton)
            .append(_this.globeButtonPanel.globeDataButton)
            .append(_this.globeButtonPanel.statisticsButton)
            .append(_this.globeButtonPanel.detailButton)
            .append(_this.globeButtonPanel.compareButton)
            .append(_this.globeButtonPanel.standardSelect)
        ;

        _this.app.ui.layout.bottom.append(_this.globeButtonPanel);
        _this.panels.push(_this.globeButtonPanel);

        //桩号导航
        _this.stakeNumPanel = new StakeNumPanel({
            "app"      : _this.app,
            "class"    : "PQIStaModule",
            "direction": 90
        });

        _this.app.ui.layout.top.append(_this.stakeNumPanel);

        _this.panels.push(_this.stakeNumPanel);

        //明细数据列表面板


        _this.statisticsPanel = new FloatPanel({
            "class": "PQIStaModule statisticsPanel"
        });
        _this.statisticsPanel.pieBlock = new ChartBlock({
            "title": "超标里程统计",
            "chart": {
                "height"     : 270,
                "width"      : 340,
                "chartOption": {
                    grid   : {
                        left        : "3%",
                        right       : "4%",
                        bottom      : "3%",
                        containLabel: true
                    },
                    tooltip: {
                        trigger        : "item",
                        backgroundColor: "rgb(1, 20, 30)",
                        borderColor    : "#333",
                        textStyle      : {
                            color: "#fff"
                        },
                        confine        : true
                    },
                    xAxis  : {
                        type: "category"
                    },
                    yAxis  : {
                        type: "value"
                    },
                    series : {
                        type: "bar"
                    }
                }
            }
        });
        _this.statisticsPanel.tableBlock = new PanelBlock({"class": "statisticsTableBlock"});
        // _this.statisticsPanel.tableBlock.title = "超标里程统计";

        _this.statisticsPanel
            .append(_this.statisticsPanel.pieBlock)
            .append(_this.statisticsPanel.tableBlock)
        ;

        _this.app.ui.layout.bottom.append(_this.statisticsPanel);
        _this.panels.push(_this.statisticsPanel);

        //明细数据列表面板
        _this.listPanel = new FloatPanel({
            "class"       : "rightPanel"
            , "showMinMax": true
            , "title"     : "PQI统计明细"
        });
        _this.listPanel.tableBlock = new TableBlock();
        _this.listPanel.tableBlock.title = "PQI统计明细";

        _this.listPanel.tableBlock.filter = {
            "param": "searchKey"
        };

        _this.listPanel.tableBlock.paramSelect = new mhjs.Select({"class": "select"});
        _this.listPanel.tableBlock.toggleParam = function (param) {

            $.each(_this.listPanel.tableBlock.head, function (i, head) {
                head.th.hide();
            });

            $.each(_this.listPanel.tableBlock.body, function (i, item) {
                item.listItem.find("td").hide();

                $.each(_this.listPanel.tableBlock.head, function (j, head) {
                    if (!head.tag || head.tag === param) {
                        head.th.show();
                        item.listItem.find("td").eq(j).show();
                        item.currentParam = param;
                    }
                });

            });

            _this.renderLevelChart(_this.items);

            _this.listPanel.tableBlock.toggleLevel(_this.listPanel.tableBlock.levelSelect.value);


        };

        _this.listPanel.tableBlock.paramSelect.on("select", function (select) {
            _this.listPanel.tableBlock.toggleParam(select.value);
        });

        _this.listPanel.tableBlock.ui.filterBlock.append(_this.listPanel.tableBlock.paramSelect);

        _this.listPanel.tableBlock.levelSelect = new mhjs.Select({"class": "select"});

        _this.listPanel.tableBlock.toggleLevel = function (level) {

            if (level !== "") {
                $.each(_this.listPanel.tableBlock.body, function (i, item) {

                    if (item.currentLevel !== level) {
                        item.listItem.hide();
                    } else {
                        item.listItem.show();
                    }

                });
            } else {
                $.each(_this.listPanel.tableBlock.body, function (i, item) {
                    item.listItem.show();
                });
            }

        };

        _this.listPanel.tableBlock.levelSelect.on("select", function (select) {
            _this.listPanel.tableBlock.toggleLevel(select.value);
        });

        _this.listPanel.tableBlock.ui.filterBlock.append(_this.listPanel.tableBlock.levelSelect);

        _this.listPanel.tableBlock.sorter = {
            "param": {
                "value": "sortKey",
                "label": "桩号"
            }
        };

        _this.listPanel.append(_this.listPanel.tableBlock);

        _this.app.ui.layout.right.append(_this.listPanel);
        _this.panels.push(_this.listPanel);

    }

    var _class = PQIStaModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "loadInit"               : {
            value: function (callback, forceReload) {

                var _this = this;

                if (forceReload || !_this.isLoaded) {

                    var queryNode = _this.app.queryManager.add(new QueryNode({
                        "title"   : "[模块] : " + _this.title,
                        "modality": true
                    }));

                    queryNode.trigger("send");

                    _this.loadMap(function (mapData) {
                        _this.app.modules.road.roadLineModule.loadInit(function () {
                            _this.app.modules.road.roadMaterialsModule.loadInit(function () {

                                queryNode.trigger("loaded");

                                _this.stakeNumPanel._startStakeNum = _this.app.modules.road.stakeNumModule.startStakeNum;
                                _this.stakeNumPanel._stopStakeNum = _this.app.modules.road.stakeNumModule.stopStakeNum;
                                _this.stakeNumPanel.update();

                                _this.stakeNumPanel.GB = _this.stakeNumPanel.addStakeNumDataPeriodLine();
                                _this.stakeNumPanel.JS = _this.stakeNumPanel.addStakeNumDataPeriodLine();

                                _this.globeButtonPanel.startStakeNumInput.value = _this.stakeNumPanel.startStakeNum.str;
                                _this.globeButtonPanel.stopStakeNumInput.value = _this.stakeNumPanel.stopStakeNum.str;

                                if (mapData) {
                                    _this.objMap = mapData.obj;
                                    _this.propertiesMap = mapData.properties;
                                    _this.dic = mapData.dic;
                                }

                                _this.statisticsPanel.tableBlock.content = _this.renderStatisticTable();

                                var headlist = [
                                    {
                                        "value" : "开始桩号",
                                        "label" : "桩号",
                                        "col"   : {"width": 135},
                                        "format": function (item, td) {

                                            // if (_this.dic.levels[item.currentLevel]) {
                                            //     td.addClass("level");
                                            //     td.addClass(_this.dic.levels[item.currentLevel].className);
                                            // }

                                            td.text(item["开始桩号"] + " > " + item["结束桩号"]);
                                        }
                                    },
                                    {
                                        "value": "朝向",
                                        "label": "朝向",
                                        "col"  : {"width": 40}
                                    },
                                    {
                                        "value": "车道",
                                        "label": "车道",
                                        "col"  : {"width": 70}
                                    }

                                ];

                                _this.listPanel.tableBlock.paramSelect.setList(
                                    (function () {
                                        var list = [];

                                        $.each(_this.dic.params, function (param, paramO) {
                                            list.push({
                                                "text" : param,
                                                "value": param
                                            });

                                            headlist.push({
                                                "value" : "param." + param,
                                                "label" : param,
                                                "tag"   : param,
                                                "format": function (item, td) {

                                                    // td.addClass("level");
                                                    // if (_this.dic.levels[item.currentLevel]) {
                                                    //     td.addClass(_this.dic.levels[item.currentLevel].className);
                                                    // } else {
                                                    //     td.addClass("noLevel");
                                                    // }
                                                    td.text(item.param[param].toFixed(0));
                                                }
                                            });

                                        });

                                        return list;

                                    }())
                                );

                                _this.listPanel.tableBlock.head = headlist;

                                _this.loadHistory({}, function (data) {

                                    var legend = [];
                                    var x = [];
                                    var series = [];

                                    $.each(_this.dic.params, function (i, param) {
                                        i = i.toLowerCase();
                                        if (data[i]) {
                                            legend.push(i.toUpperCase());
                                            $.each(data[i], function (time, data) {
                                                if (x.indexOf(time) < 0) {
                                                    x.push(time);
                                                }
                                            });
                                        }
                                    });

                                    $.each(_this.dic.params, function (i, param) {
                                        i = i.toLowerCase();
                                        if (data[i]) {
                                            var list = [];
                                            $.each(x, function (j, time) {
                                                if (data[i][time]) {
                                                    list.push(data[i][time].toFixed(4));
                                                } else {
                                                    list.push("-");
                                                }
                                            });
                                            series.push({
                                                "name"  : i.toUpperCase(),
                                                "data"  : list,
                                                "type"  : "line",
                                                "symbol": "circle"
                                            });
                                        }
                                    });

                                    _this.globeChartPanel.hisBlock.chart.setOption({
                                        legend: {
                                            data: legend
                                        },
                                        xAxis : {
                                            data: x
                                        },
                                        series: series
                                    });

                                    _this.historyData = series;
                                    _this.globeButtonPanel.searchButton.trigger("click");
                                });

                                _this.globeChartPanel.pieBlock.chart.setOption({
                                    legend: {
                                        data: (function () {
                                            var list = [];
                                            $.each(_this.dic.levels, function (level, obj) {
                                                list.push(level);
                                            });
                                            return list;
                                        }())
                                    }
                                });

                                _this.listPanel.tableBlock.levelSelect.setList(
                                    (function () {

                                        var list = [
                                            {
                                                "text" : "全部",
                                                "value": ""
                                            }
                                        ];

                                        $.each(_this.dic.levels, function (level, obj) {
                                            list.push({
                                                "text" : level,
                                                "value": level
                                            });
                                        });

                                        return list;

                                    }())
                                );

                                _this.initComparePanel();

                                _this.isLoaded = true;

                                _this.trigger("loadInit");
                                callback && callback();

                            });

                        });

                    });

                } else {
                    callback && callback();
                }

            }
        },
        "loadHistory"            : {
            value: function (data, callback) {

                var _this = this;

                if (_this.historyRequest) {
                    _this.historyRequest.send(data, function (result) {
                        callback && callback(result.data);
                    });
                }
            }
        },
        "renderData"             : {
            value: function (option, callback) {
                var _this = this;

                if (option && option.simpleEqual(_this.currentStatisticsOption)) {
                    callback && callback();
                } else {

                    _this.app.queryManager.modalityLoading.open();
                    _this.app.queryManager.modalityLoading.info = "正在加载数据";

                    _this.loadData(option, function (result) {
                        _this.currentStatisticsOption = option;
                        _this.currentList = result;
                        _this.renderList(_this.currentList || []);
                        _this.listPanel.tableBlock.paramSelect.select(4);
                        _this.toggleStandard();

                        _this.app.queryManager.modalityLoading.close();

                        _this.globeDataPanel.PQIData.count = Number(_this.historyData[0].data[_this.globeButtonPanel.yearSelect.selectIndex]).toFixed(2);

                        callback && callback(result);
                    });
                }


            }
        },
        "open"                   : {
            value: function (forceReload) {
                var _this = this;

                _this.loadInit(function () {
                    _this.isOpened = true;

                    $.each(_this.items, function (i, item) {
                        item.open();
                    });

                    _this.globeChartPanel.open(false);
                    _this.globeChartPanel.max(false);
                    _this.globeDataPanel.open(false);
                    _this.globeButtonPanel.open(false);
                    _this.stakeNumPanel.open(false);
                    _this.listPanel.open(false);
                    _this.listPanel.max(false);

                    _this.trigger("open");
                    _this.trigger("toggle");
                }, forceReload);


            }
        },
        "openStatistics"         : {
            value: function () {
                var _this = this;
                _this.globeChartPanel.min(false);
                _this.listPanel.min(false);
                _this.statisticsPanel.open(false);
                _this.globeButtonPanel.addClass("statisticsOpen");
            }
        },
        "openDetail"             : {
            value: function () {
                var _this = this;
                _this.listPanel.max(false);
                _this.globeChartPanel.max(false);
                _this.statisticsPanel.close(false);
                _this.globeButtonPanel.removeClass("statisticsOpen");
            }
        },
        "clearStatistics"        : {
            value: function () {
                var _this = this;

                $.each(_this.items, function (i, item) {
                    item.remove();
                });
                _this.items = [];
                _this.listPanel.tableBlock.clear();
                _this.stakeNumPanel.resetStakeNumDataLine(_this.stakeNumPanel.GB);
                _this.stakeNumPanel.resetStakeNumDataLine(_this.stakeNumPanel.JS);

            }
        },
        "renderLevelItem"        : {
            value: function (data, td) {

                var _this = this;

                if (_this.dic.levels[data.level]) {
                    td.css({
                        "color": _this.dic.levels[data.level].color
                    });
                }

                return data.value.toFixed(0);
            }
        },
        "getStatisticTableObject": {
            value: function () {

                var _this = this;
                var result = {};
                $.each(_this.dic.statisticsTable.directions, function (i, direction) {
                    result[direction] = {};

                    $.each(_this.dic.statisticsTable.roadLines, function (j, roadLine) {
                        result[direction][roadLine] = {};
                        $.each(_this.dic.statisticsTable.params, function (k, param) {
                            result[direction][roadLine][param] = {
                                "counters": []
                            };
                        });
                    });
                });

                return result;
            }
        },
        "countStatisticTable"    : {
            value: function (list) {

                var _this = this;

                var chartSeries = [];

                $.each(_this.statisticsTableObject, function (direction, roadLines) {

                    $.each(roadLines, function (roadLine, params) {

                        $.each(params, function (param, paramObj) {

                            paramObj.pqiStatistics = [];
                            paramObj.exceeds = [];
                            paramObj.distance = 0;
                            paramObj.exceedDistance = 0;
                            paramObj.counters[0].empty().removeClass("noData");
                            paramObj.counters[1].empty().removeClass("noData");

                            $.each(list, function (l, pqiStatics) {

                                if (
                                    pqiStatics["朝向"] === direction
                                    && pqiStatics["车道"] === roadLine
                                    && pqiStatics.param[param]
                                ) {

                                    paramObj.pqiStatistics.push(pqiStatics);
                                    paramObj.distance += Math.abs(pqiStatics.stopStakeNum.distance - pqiStatics.startStakeNum.distance);

                                    if (_this.getLevel(param, pqiStatics.param[param], _this.currentStandard) !== "优") {
                                        paramObj.exceeds.push(pqiStatics);
                                        paramObj.exceedDistance += Math.abs(pqiStatics.stopStakeNum.distance - pqiStatics.startStakeNum.distance);
                                    }


                                }

                            });

                            if (paramObj.pqiStatistics.length > 0) {
                                paramObj.counters[0].text((paramObj.exceedDistance / 1000).toFixed(3));
                                paramObj.counters[1].text((paramObj.exceedDistance / paramObj.distance * 100).toFixed(2));

                                chartSeries.push({
                                    "name" : param,
                                    "value": (paramObj.exceedDistance / 1000).toFixed(3)
                                });

                            } else {
                                paramObj.counters[0].addClass("noData");
                                paramObj.counters[1].addClass("noData");
                            }


                        });
                    });
                });

                _this.statisticsPanel.pieBlock.chart.setOption(
                    {
                        series: {
                            data: chartSeries
                        }
                    }
                );

            }
        },
        "renderLevelChart"       : {
            value: function (list) {

                var _this = this;

                var series = {};

                $.each(_this.dic.levels, function (level, obj) {
                    series[level] = 0;
                });

                $.each(list, function (i, pqiStatics) {
                    if (pqiStatics.currentLevel) {
                        series[pqiStatics.currentLevel] += Math.abs(pqiStatics.stopStakeNum.distance - pqiStatics.startStakeNum.distance);
                    }
                });

                // _this.globeChartPanel.pieBlock.title =
                //     _this.listPanel.tableBlock.paramSelect.selectChild.text
                //     + " [ "
                //     + _this.globeButtonPanel.directSelect.selectChild.text
                //     + " / " + _this.globeButtonPanel.roadLineSelect.selectChild.text
                //     + " / " + _this.globeButtonPanel.startStakeNumInput.value
                //     + " > " + _this.globeButtonPanel.stopStakeNumInput.value
                //     + " / " + _this.globeButtonPanel.standardSelect.selectChild.text
                //     + " ]"
                // ;


                _this.globeChartPanel.pieBlock.chart.setOption(
                    {
                        series: {
                            data: (function () {
                                var list = [];
                                $.each(_this.dic.levels, function (level, obj) {

                                    if (series[level] > 0) {
                                        list.push({
                                            "name"     : level,
                                            "value"    : series[level],
                                            "itemStyle": {
                                                "color": obj.color
                                            }
                                        });
                                    }

                                });
                                return list;
                            }())
                        }
                    }
                );

            }
        },
        "renderList"             : {
            value: function (list) {

                var _this = this;

                _this.clearStatistics();

                $.each(list, function (i, item) {

                    if (_this.objMap) {
                        item = _this.objMap.format(item);
                    }

                    item.app = _this.app;
                    item.icon = _this.icon;
                    item.dic = _this.dic;

                    var positions = _this.app.modules.road.roadLineModule.getRoadSection({
                        "startStakeNum": item["开始桩号"],
                        "stopStakeNum" : item["结束桩号"],
                        "direction"    : _this.directionCodeDic[item.directionCode],
                        "roadTrackNum" : item["车道序号"]
                    });

                    if (positions.length > 0) {
                        item.positions = positions;
                    }

                    var pqiStatistic = new PQIStatistic(item);
                    _this.items.push(pqiStatistic);

                    pqiStatistic._standard = _this.currentStandard;
                    pqiStatistic._currentParam = _this.listPanel.tableBlock.paramSelect.value;

                    if (pqiStatistic["车道"] === "整体") {
                        pqiStatistic.stakeNumNode = {
                            "GB": _this.stakeNumPanel.GB[pqiStatistic.startStakeNum.no],
                            "JS": _this.stakeNumPanel.JS[pqiStatistic.startStakeNum.no]
                        };
                    }

                    pqiStatistic.block = new PQIBlock({
                        properties: pqiStatistic
                    });

                    pqiStatistic.on("click", function (event) {
                        _this.activeItem(pqiStatistic);
                        _this.app.pop.target = pqiStatistic;
                        _this.app.pop.content = pqiStatistic.block;
                        _this.app.pop.position = event.position;
                        _this.app.pop.open();
                    });

                    pqiStatistic.listItem = _this.listPanel.tableBlock.add(pqiStatistic);
                    pqiStatistic.listItem.pqiStatistic = pqiStatistic;

                    // pqiStatistic.listItem = new ListItem({
                    //     "title"    : pqiStatistic.title,
                    //     "subtitle" : pqiStatistic["道路"],
                    //     "icon"     : _this.icon.base64,
                    //     "pqiStatistic"      : pqiStatistic
                    // });

                    pqiStatistic.listItem.on("click", function () {
                        _this.activeItem(pqiStatistic);
                        pqiStatistic.layer.active();

                        // _this.detailPanel.propertiesBlock.title = pqiStatistic.title;
                        // _this.detailPanel.propertiesBlock.map = _this.propertiesMap;
                        // _this.detailPanel.propertiesBlock.properties = pqi;
                        // _this.detailPanel.open();
                    });

                    pqiStatistic.listItem.on("hide", function (listItem) {
                        listItem.pqiStatistic.close();
                    });

                    pqiStatistic.listItem.on("show", function (listItem) {
                        listItem.pqiStatistic.open();
                    });

                    pqiStatistic.open();


                });

                _this.listPanel.tableBlock.filter.list = _this.listPanel.tableBlock.body;
                _this.listPanel.tableBlock.sorter.list = _this.listPanel.tableBlock.body;

                _this.countStatisticTable(_this.items);
                _this.renderLevelChart(_this.items);

                _this.countComparePanel();

            }
        },
        "renderStatisticTable"   : {
            value: function () {

                var _this = this;

                _this.statisticsTableObject = _this.getStatisticTableObject();

                var table = new mhjs.Table();
                var thead = new mhjs.Thead();
                var tbody = new mhjs.Tbody();

                table
                    .append(thead)
                    .append(tbody)
                ;

                var theadtr = new mhjs.Tr();
                var theadtr2 = new mhjs.Tr();

                thead
                    .append(theadtr)
                    .append(theadtr2)
                ;

                $.each(_this.dic.statisticsTable.head, function (i, item) {

                    var th = new mhjs.Th();
                    th.text(item);
                    th.attr("rowspan", 2);
                    theadtr.append(th);
                });


                var chartXAxis = [];


                $.each(_this.dic.statisticsTable.params, function (i, item) {

                    var th = new mhjs.Th();
                    th.text(_this.dic.params[item].label.short + " " + item);
                    th.attr("colspan", 2);
                    theadtr.append(th);

                    chartXAxis.push(item);

                    $.each(_this.dic.statisticsTable.counts, function (j, item2) {
                        var th = new mhjs.Th();
                        th.text(item2);
                        theadtr2.append(th);
                    });

                });

                $.each(_this.dic.statisticsTable.directions, function (i, direction) {

                    var tr = new mhjs.Tr();
                    tbody.append(tr);

                    var td = new mhjs.Td();
                    td.text(direction);
                    td.attr("rowspan", _this.dic.statisticsTable.roadLines.length);

                    tr.append(td);

                    $.each(_this.dic.statisticsTable.roadLines, function (j, roadLine) {

                        var td = new mhjs.Td();
                        td.text(roadLine);

                        if (j === 0) {
                            var currentTr = tr;

                        } else {
                            var tr2 = new mhjs.Tr();
                            tbody.append(tr2);
                            var currentTr = tr2;
                        }

                        currentTr.append(td);

                        $.each(_this.dic.statisticsTable.params, function (k, param) {
                            $.each(_this.dic.statisticsTable.counts, function (l, counter) {
                                var td = new mhjs.Td();
                                currentTr.append(td);
                                _this.statisticsTableObject[direction][roadLine][param].counters.push(td);
                            });

                        });

                    });

                });

                _this.statisticsPanel.pieBlock.chart.setOption({xAxis: {data: chartXAxis}});

                return table;

            }
        },
        "initComparePanel"       : {
            value: function () {
                var _this = this;

                _this.compareChartPanel.dataTable = {};

                var table = new mhjs.Table();
                var thead = new mhjs.Thead();
                var tbody = new mhjs.Tbody();

                table
                    .append(thead)
                    .append(tbody)
                ;

                var theadtr = new mhjs.Tr();

                thead
                    .append(theadtr)
                ;

                $.each(_this.dic.compareTable.head, function (i, item) {
                    var th = new mhjs.Th();
                    th.text(item);
                    theadtr.append(th);
                });

                $.each(_this.dic.compareTable.params, function (i, item) {

                    _this.compareChartPanel.dataTable[item] = {};

                    var tr = new mhjs.Tr();

                    $.each(_this.dic.compareTable.head, function (j, item2) {
                        var td = new mhjs.Td();

                        if (j === 0) {
                            td.text(_this.dic.params[item].label.short);
                        } else {
                            _this.compareChartPanel.dataTable[item][item2] = {
                                items: [],
                                td   : td
                            };

                            td.on("click", function () {
                                table.find("td").removeClass("active");
                                td.addClass("active");
                                _this.renderCompareDetail(_this.compareChartPanel.dataTable[item][item2].items);
                            });
                        }

                        tr.append(td);


                    });
                    tbody.append(tr);
                });

                _this.compareChartPanel.tableBlock.content = table;


            }
        },
        "countComparePanel"      : {
            value: function () {
                var _this = this;

                $.each(_this.compareChartPanel.dataTable, function (param, paramObj) {

                    paramObj["规范指标"].items = [];
                    paramObj["内部指标"].items = [];
                    paramObj["差值"].items = [];

                });

                _this.compareChartPanel.listBlock.clear();


                $.each(_this.items, function (i, item) {

                    $.each(_this.dic.compareTable.params, function (i, param) {

                        var gbLevel = _this.getLevel(param, item.param[param], "GB");
                        var jsLevel = _this.getLevel(param, item.param[param], "JS");

                        if (gbLevel && gbLevel !== "优") {
                            _this.compareChartPanel.dataTable[param]["规范指标"].items.push(item);
                        }

                        if (gbLevel && jsLevel !== "优") {
                            _this.compareChartPanel.dataTable[param]["内部指标"].items.push(item);
                        }

                        if (gbLevel === "优" && jsLevel !== "优") {
                            _this.compareChartPanel.dataTable[param]["差值"].items.push(item);
                        }

                    });

                });

                $.each(_this.compareChartPanel.dataTable, function (param, paramObj) {

                    paramObj["规范指标"].td.text(paramObj["规范指标"].items.length + " KM");
                    paramObj["内部指标"].td.text(paramObj["内部指标"].items.length + " KM");
                    paramObj["差值"].td.text(paramObj["差值"].items.length + " KM");

                });

            }
        },
        "renderCompareDetail"    : {
            value: function (items) {
                var _this = this;

                var table = new mhjs.Table();
                var thead = new mhjs.Thead();
                var tbody = new mhjs.Tbody();

                table
                    .append(thead)
                    .append(tbody)
                ;

                var theadtr = new mhjs.Tr();

                thead
                    .append(theadtr)
                ;

                $.each([
                    "序号",
                    "车道",
                    "方向",
                    "桩号",
                    "公里数"
                ], function (i, item) {
                    var th = new mhjs.Th();
                    th.text(item);
                    theadtr.append(th);
                });

                $.each(items, function (i, item) {
                    var tr = new mhjs.Tr();

                    var td = new mhjs.Td();
                    td.text(i + 1);
                    tr.append(td);

                    var td2 = new mhjs.Td();
                    td2.text(item["车道"]);
                    tr.append(td2);

                    var td3 = new mhjs.Td();
                    td3.text(item["朝向"]);
                    tr.append(td3);

                    var td4 = new mhjs.Td();
                    td4.text(item["开始桩号"]);
                    tr.append(td4);

                    var td5 = new mhjs.Td();
                    td5.text(Math.abs((item.stopStakeNum.distance - item.startStakeNum.distance) / 1000).toFixed(2) + " KM");
                    tr.append(td5);

                    tr.on("click", function () {
                        if (item.listItem) {
                            item.listItem.trigger("click");
                        }
                    });

                    tbody.append(tr);
                });

                _this.compareChartPanel.listBlock.content = table;

            }
        },
        "toggleStandard"         : {
            value: function (standard) {
                var _this = this;
                _this.currentStandard = standard;

                $.each(_this.listPanel.tableBlock.body, function (i, item) {
                    item.standard = standard;
                });

                _this.countStatisticTable(_this.items);
                _this.renderLevelChart(_this.items);
            }
        },
        "toggle"                 : {
            value: function () {
                var _this = this;
                if (_this.isOpened) {
                    _this.close();
                } else {
                    _this.open();
                }
            }
        },
        "openPanel"              : {
            value: function () {
                var _this = this;
                if (!_this.isOpened) {
                    _this.open();
                }

                _this.listPanel.open();
                _this.isPanelOpened = true;
                _this.trigger("openPanel");

            }
        },
        "close"                  : {
            value: function () {
                var _this = this;
                _this.closePanel();
                $.each(_this.items, function (i, item) {
                    item.close();
                });
                _this.isOpened = false;
                _this.trigger("close");
                _this.trigger("toggle");
            }
        },
        "closePanel"             : {
            value: function (stopPropagation) {
                var _this = this;

                _this.globeButtonPanel.removeClass("statisticsOpen");

                _this.closeAllPanel();
                _this.isPanelOpened = false;
                stopPropagation !== false && _this.trigger("closePanel");
            }
        },
        "activeItem"             : {
            value: function (item) {
                var _this = this;
                _this.unActiveAllItem();
                item.active();
                item.listItem.addClass("active");
                item.listItem.parent().animate({"scrollTop": item.listItem.dom[0].offsetTop - 30});

            }
        },
        "unActiveAllItem"        : {
            value: function () {
                var _this = this;
                $.each(_this.items, function (i, item) {
                    item.active(false);
                    item.listItem.removeClass("active");
                });
            }
        },
        "getLevel"               : {
            value: function (param, value, standard) {
                var _this = this;

                var result;
                var currentLevels = _this.dic.params[param].levels;

                if (currentLevels) {
                    $.each(currentLevels, function (i, level) {

                        var currentLevel = level[standard] || level.GB;
                        var max = Number(currentLevel.split(",")[0]);
                        var min = Number(currentLevel.split(",")[1]);

                        if (value >= min && value < max) {
                            result = i;
                            return false;
                        }

                    });

                }

                return result;

            }
        }
    });

    return _class;

});